// pages/project/index.js
const app = getApp()
const{
  projectList
} =require('../../api/project')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    projectName:'',
    task_list:[],
    pageNo:1,
    pageSize:10,
    category:'2',
    active:"2",
    project_list:[],
    finished: false,
    userInfo:null,
    showTab:true,
    isLogin:false,
  },
  tabclick(e){
    this.data.category = e.detail.name
    this.data.pageNo=1
    this.data.project_list=[]
    this.init()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo:app.userInfo,
      isLogin:app.isLogin
    })
    this.init()
  },
  init(){
    wx.showLoading({
      title: '数据加载中~',
    })
    console.log('this.data.searcy',this.data.projectName)
    projectList({type:this.data.category,pageNo:this.data.pageNo,pageSize:this.data.pageSize,projectName:this.data.projectName}).then(res=>{
      const projectList = this.data.project_list;
      let templateList=res.data.list
      if(!templateList.length>0){
        this.data.finished=true
      }else{
        this.setData({
          project_list:projectList.concat(templateList)
        })
      }
     
      this.setData({
        project_list:this.data.project_list ||[]
      })
      console.log(this.data.project_list.length)
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
      wx.stopPullDownRefresh();
    })
  },
  searchPage(){
    wx.navigateTo({
      url: '/pages/search/index',
    })
  },
  onClickToMap(){
    wx.navigateTo({
      url: '/pages/map/index',
    })
  },
  onChange(event){

    this.data.pageNo=1
    this.data.project_list=[]
    this.data.projectName=event.detail

    this.init()

    //this.init()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.pageNo=1
    this.data.project_list=[]
    this.data.finished=false
    this.init()

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.finished){
      this.data.pageNo=parseInt(this.data.pageNo+1)
      this.init()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})